跳转至

CLAUDE.md 为什么会不断膨胀?智能体编程中的“灾难性记忆”现象

文章背景与核心概要

在当前的软件开发中,像 CLAUDE.md 这样的智能体编程(Agentic Coding)文档和配置文件在活跃的代码仓库中会不可避免地无限膨胀,通常只有在项目归档或被彻底重写时才会停止增长。本文深入探讨了这一现象,并将其归因于记忆不完美(imperfect recall):追加新指令的成本极低且直截了当,但一旦原始的设计理由丢失,在不引入正确性回退的前提下安全删除一条过时指令的成本将呈指数级上升(\(\mathcal{O}(2^{|D|})\))。

作者将持续学习中“灾难性遗忘”(catastrophic forgetting)的反面现象命名为灾难性记忆(catastrophic remembering)。该论文的核心贡献包括:通过对 1,867 个代码仓库中 247,694 个指令生命周期的实证分析,发现智能体提示词在其生命周期内规模会扩大两倍以上(+226%),每个提交平均净增 4.9 条指令,且指令越老被删除的概率越低;证明了通过提示词注释(Prompt Comments)编码潜在推理,可以成功消除 99.3% 的多余指令,将增长率从 +211.3% 降至 +1.4%;并在真实世界的 WildIFEval 上证明了结构化提示词注释能将智能体指令遵循性能提升高达 23.1%,从而引出一个根本性问题:“如果英语成了新代码,为什么我们现在还没有注释?”


为什么 CLAUDE.md 会不断膨胀?智能体编程中的“灾难性记忆”

作者: Kushal Chakrabarti
主要主题: 人工智能 (cs.AI)
次要主题: 机器学习 (cs.LG)、软件工程 (cs.SE)
arXiv ID: arXiv:2608.11095 [cs.AI]
提交时间: 2026年8月11日
许可协议: 知识共享署名 4.0
license icon


摘要

Agentic coding READMEs like CLAUDE.md grow without bound in real repositories, stopping only when the repository retires or someone rewrites the file wholesale. We trace this to imperfect recall: appending an instruction is always cheap, but once an instruction's rationale is gone, deleting it without risking a correctness regression costs \(\mathcal{O}(2^{|D|})\) in a prompt of \(|D|\) instructions. We name the resulting divergence catastrophic remembering, the inverse of catastrophic forgetting around which continual learning is organized.

First, we characterize this phenomenon across 247,694 instruction lifetimes in 1,867 repositories: agentic prompts grow without bound, more than tripling over their lifetime (+226%), gaining +4.9 net instructions every commit; further, the older an instruction gets, the less likely it is to be deleted (log-hazard -0.032/commit). Then, we show that prompt comments can halt the growth: inverting IFEval yields verifiable worlds whose optimal prompts are known, and there comments encoding latent reasoning remove 99.3% of excess instructions (+211.3% to +1.4%). Finally, applying the same inversion to WildIFEval, we show that prompt comments can improve real-world agentic instruction-following by up to 23.1%. If English is the new code, why don't we have comments yet?

智能体编程的 README 文件(如 CLAUDE.md)在真实的代码仓库中会无限增长,只有当仓库退役或有人将该文件整体重写时才会停止。我们将此归因于记忆不完美:追加指令总是成本低廉的,但一旦指令的初衷丢失,在一个包含 \(|D|\) 条指令的提示词中,冒着引入正确性回退的风险将其删除的成本为 \(\mathcal{O}(2^{|D|})\)。我们将由此产生的分歧命名为灾难性记忆(catastrophic remembering),这正是持续学习所围绕的“灾难性遗忘”的反面。

首先,我们对 1,867 个代码仓库中的 247,694 个指令生命周期进行了特征分析:智能体提示词呈无界增长,在其生命周期内扩大了两倍多(+226%),每个提交净增 +4.9 条指令;此外,指令越老,被删除的可能性就越小(对数风险为 -0.032/提交)。然后,我们证明了提示词注释可以阻止这种增长:反转 IFEval 可以产生可验证的世界,其最佳提示词是已知的,其中编码了潜在推理的注释消除了 99.3% 的多余指令(从 +211.3% 降至 +1.4%)。最后,将同样的逆向方法应用于 WildIFEval,我们证明了提示词注释可以将现实世界中的智能体指令遵循能力提升高达 23.1%。如果英语成了新代码,为什么我们现在还没有注释?


全文与资源